#! /usr/bin/python
import curses
from curses import wrapper
from multiprocessing import connection
from os import fork

__author__="simon"
__date__ ="$Feb 13, 2010 11:30:36 PM$"

class buddyList():
    def __init__(self,stdscr):
        self.stdscr = stdscr
        self.buddies = {}
        self.nlines, self.ncols = 25,12
        self.window = curses.newpad(self.nlines, self.ncols)
        self.window.box(ord("|"),ord("-"))
        
    def draw(self):
        self.window.clear()
        y,x = 0,0
        for name in self.buddies.keys():
            self.window.addstr(y,x,name)
            y+=1
        self.window.refresh(0,0,0,0,15,12)

def main(stdscr):
    stdscr.nodelay(True)
    address = ("localhost",6000)
    conn = connection.Client(address)
    curses.delay_output(10)
    buddies = ["Matt","Test","Another Test","Blarg","LOL"]
    buddyl = buddyList(stdscr)
    for name in buddies:
        buddyl.buddies[name] = None
        buddyl.draw()
        stdscr.getstr(10,10)
    while(1):
        try:
            if conn.poll():
                data = conn.recv()
        except:
            pass
        key = stdscr.getch(4,4)
        if key != -1:
            stdscr.addstr(5,5,"yarr")
            stdscr.addstr(4,4,str(key))
            
if __name__ == "__main__":
    wrapper(main)
